package net.zjitc.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StreamCorruptedException;

/**
 * Created by Administrator on 2017/9/28.
 */
@WebServlet(name = "IpServlet",urlPatterns = "/ipServlet")
public class IpServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /**
         *  1.先从请求中获得对方IP
         *  2.拿对方的IP和被禁用的比较，是否相同，如果相同：提示：被禁用
         *   如果不同，提示：欢迎。。。
         */
          response.setContentType("text/html;charset=utf-8");
          PrintWriter out = response.getWriter();
          String ip =  request.getRemoteAddr();
          if ("171.68.8.26".equals(ip)){  //127.0.0.1
              out.write("被禁用.....");
          }else {
              out.write("欢迎。。。。。");
          }

    }
}
